package com.wandian.robot;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import com.wandian.executor.TimerMgr;
import com.wandian.texas.DataPacket;
import com.wandian.texas.GamePool;
import com.wandian.texas.protocol.Protocol;
import com.wandian.util.Log;
import com.wandian.util.RandomUtil;

/**
 * 机器人
 * 
 * @author long
 * @Create 2012-11-13 下午2:45:40
 * @QQ 108232706
 * @version 1.0
 * @description Robot
 */
/**
 * @author long
 * @date 2012-11-15 下午12:05:58
 * @qq 108232706
 * @description Robot
 */
public class Robot {
	private int userid;
	public String username;
	//	private final Object obj;
	private long lastSyncTime;
	private int acceleratCount;
	public SocketChannel socketChannel = null;

	public void close() {
		try {
			SelectionKey key = socketChannel.keyFor(RobotMgr.selector);
			if (key != null)
				key.cancel();
			socketChannel.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public final ByteBuffer SendBuffer = ByteBuffer.allocate(10 * 1024);
	public final ByteBuffer RecvBuffer = ByteBuffer.allocate(10 * 1024);
	// 原子方式更新
	private final AtomicBoolean hasReceiveData = new AtomicBoolean(false);// 判断该session是否有接收的数据
	private final AtomicBoolean hasSendData = new AtomicBoolean(false);// 判断该session是否有发送的数据
	public DataPacket dataPacket = new DataPacket(10 * 1024);
	public DataPacket recDataPacket = new DataPacket(10 * 1024);
	public boolean isUseRecDataPacket = false;
	public boolean connected = false;
//	public StringBuilder StatusList = new StringBuilder();
	// ---
	public String name;
	public int sex;
	// public String btd;
	// public String city;
	// public int invite;
	// public int gp;
	// public int mtime;
	//	public String email;
	//	public String moible;
	// public int sta;
	// public int lgtm;
	// public int lxlg;
	// public String icon;
	// public int personId;
	// public int vip;
	// public int viptime;
	// public int level = 3;
	public int score = 1;
	public int gold = 1;
	public float money = 1;
	// public int honor;
	// public int star;
	// public int hasNM;
	// public int bankAssets;
	// public int bankpasswd = 0;
	// public String realname = "";
	// public String idontity = "";
	// public int canaward = 0;
	// public int winGame;
	// public int sumGame;
	// public int rank;
	// public int winRank;
	// public int lotcount;
	// public int isopen;
	// public int isdayfrist;
	// public int yellowvip;
	// public int isyearvip;
	// public int tcost;
	// public int isaddf;
	// public int isInviteopen;

	public int roomCount;
	public int floorCount;
	public int bettime;
	public int seat;
	public int seatId;
	public int notEmptyCount;
	List<RoomVo> arrRoom = new ArrayList<RoomVo>();
	//	Map<Integer, RoomVo> roomMap = new HashMap<Integer, RoomVo>();
	RoomVo[] roomMap = null;
	/**
	 * 9个坐位玩家游戏数据，PlayerVo
	 * 
	 * @default
	 */
	private final PlayerVo[] _arrSitInfo = new PlayerVo[9];
	/**
	 * 进出房间玩家游戏数据，PlayerVo
	 * 
	 * @default
	 */
	private final ArrayList<PlayerVo> _arrInRoomPlayer = new ArrayList<PlayerVo>();
	private final ArrayList<Integer> _arrInRoomUserid = new ArrayList<Integer>();
	public RoomVo _objRoom;
	public PlayerVo curPlayer = new PlayerVo();
	int curRoomId = -1;
	int[] arrRoomSeat;

	/**
	 * 给机器人指配房间,(id-begin)%roomCount
	 */
	public int roomId;
	public int id;

	public Robot(String _userName, int id) {
		this.username = _userName;
		this.id = id;
		//		this.obj = new Object();
		SendBuffer.order(ByteOrder.LITTLE_ENDIAN);
		RecvBuffer.order(ByteOrder.LITTLE_ENDIAN);
		// int port, String localAddress, int localPort, IoHandlerAdapter
		// handler, int type)
		// this.client = new LinkedClient(userId, "127.0.0.1", 9999,
		// "127.0.0.1", 9999, RobotMgr.handler, 1);
	}

	public boolean connect() throws IOException {
		socketChannel = SocketChannel.open();
		//		InetAddress ia = InetAddress.getLocalHost();
		InetSocketAddress isa = new InetSocketAddress(RobotMgr.GameserverIp, RobotMgr.GameserverPort);
		socketChannel.connect(isa); // 采用阻塞模式连接服务器
		socketChannel.configureBlocking(false); // 设置为非阻塞模式
		this.register();
		connected = true;
		return true;
	}

	public void requestRoomList() {
		synchronized (this.dataPacket) {
			Log.debug(this + "请求房间列表");
//			//StatusList.append("reqRoomList=>");
			this.setCmd(Protocol.RoomListCmd);
			this.writeBegin();
			this.writeByte((byte) 0);
			this.writeEnd();
			this.SendData();
		}
	}

	public void responseRoomList() {
		roomCount = this.readInt();
		if (id - RobotMgr.robotBegin + 1 > (roomCount - RobotMgr.robotStartRoomId + 1) * 9)
			this.roomId = (id - RobotMgr.robotBegin) % roomCount + 1;
		else {
			this.roomId = (id - RobotMgr.robotBegin) / 9 + RobotMgr.robotStartRoomId;
		}
		roomMap = new RoomVo[roomCount + 1];
		//		if (id - RobotMgr.robotBegin + 1 < roomCount)
		//			this.roomId = (id - RobotMgr.robotBegin) / 9;//1~9号，进1号房间
		//		else
		//			this.roomId = (id - RobotMgr.robotBegin) % roomCount;//平分在每间房
		this.readByte();//enableRoomCode
		floorCount = this.readInt();
		bettime = this.readInt();
		int seat = this.readInt();
		float minBlind = this.readFloat();
		float maxBlind = this.readFloat();
		float minTake = this.readFloat();
		float maxTake = this.readFloat();
		Log.debug("[RoomInfoProxy]获取房间列表roomCount " + roomCount + ",minBlind " + minBlind + " maxBlind " + maxBlind + " seat " + seat + " minTake " + minTake + " maxTake" + maxTake);
		notEmptyCount = this.readInt();
		int count = 0;
		RoomVo roomVo;
		while (count < roomCount) {
			count++;
			roomVo = new RoomVo();
			roomVo.id = count;
			roomVo.minBlind = minBlind;
			roomVo.maxblind = maxBlind;
			roomVo.minStake = minTake;
			roomVo.maxStake = maxTake;
			roomVo.seat = seat;
			roomVo.playerNum = 0;
			roomVo.isvip = 0;
			roomVo.close = 0;
			roomVo.password = "";
			arrRoom.add(roomVo);
			//			roomMap.put(count, roomVo);
			roomMap[roomVo.id] = roomVo;
		}

		count = 0;
		int rid = 0;
		while (count < notEmptyCount) {
			count++;
			rid = this.readInt();
			roomVo = arrRoom.get(rid - 1);
			// roomVo.id=rid;
			roomVo.name = this.readString();
			roomVo.minBlind = this.readFloat();
			roomVo.maxblind = this.readFloat();
			roomVo.minStake = this.readFloat();
			roomVo.maxStake = this.readFloat();
			roomVo.seat = this.readInt();
			roomVo.playerNum = this.readInt();
			//			roomVo.isvip = this.readInt();
			//			roomVo.close = this.readInt();
			//			roomVo.password = this.readString();
		}
		this.readEnd();
		// 随机登陆房间
		RobotMgr.run(new Runnable() {
			public void run() {
				requetEnterRoom();
			}
		});
	}

	/**
	 * 如果分配的房间存在，进入指定的房间，否则向服务端请求随机进入
	 */
	public void requetEnterRoom() {
		RoomVo room = getRandomRoom();
		if (room != null) {
			//			//StatusList.append("指派房," + this.roomId);
			requestRoomInfo(room);
		} else {
//			//StatusList.append("快速进入房间,");
			requestFastEnterRoomData();
		}
	}

	public void requestRoomInfo(RoomVo room) {
		curRoomId = room.id;
		synchronized (this.dataPacket) {
			this.setCmd(Protocol.EnterRoomCmd);
			this.writeBegin();
			this.writeByte((byte) 0);
			this.writeInt(room.id);
			this.writeEnd();
			this.SendData();
		}
	}

	public void requestFastEnterRoomData() {
		synchronized (this.dataPacket) {
			this.setCmd(Protocol.EnterRoomCmd);
			this.writeBegin();
			this.writeByte((byte) 4);
			this.writeEnd();
			this.SendData();
		}
	}

	public void responseFastEnterRoomData() {
		/*short errId = */this.readByte();
		int roomId = this.readInt();
		this.readEnd();
//		//StatusList.append("roomId:" + roomId);
		if (roomId == -1) {
			Log.error(this + "没找到合适的房间");
			// 重新找其他房间
		} else {
			//			requestRoomInfo(roomMap.get(roomId));
			requestRoomInfo(roomMap[roomId]);
		}

	}

	public RoomVo getRandomRoom() {
		return arrRoom.get(this.roomId - 1);
		/*
		if (RandomUtil.next(2) == 1) {
			Log.debug(this + "准备进指定房");
			int index = RandomUtil.next(arrRoom.size());
			return arrRoom.get(index);
		} else {
			Log.debug(this + "准备进随机房");
			return null;
		}*/
	}

	short errId;

	public void responseRegister() {
		errId = this.readByte();
		this.readEnd();
		curEnterRoomCount++;
		if (errId == 1) {
			//			_objRoom = roomMap.get(curRoomId);
			_objRoom = roomMap[curRoomId];
			arrRoomSeat = this.getRoomSit(_objRoom.seat);
			Log.debug(String.format("[%s] %s", this, "进房间成功!"));
			//StatusList.append("Reg进房间" + curRoomId + "成功,curEnterRoomCount " + curEnterRoomCount);
		} else {
			Log.error("登陆房间失败！");
			arrRoomSeat = null;
			_objRoom = null;
			//StatusList.append("Reg进房间" + curRoomId + "失败,curEnterRoomCount " + curEnterRoomCount);
			// 重新进其他房间
			// 随机登陆房间
			RobotMgr.run(new Runnable() {
				public void run() {
					requetEnterRoom();
				}
			});
		}
	}

	ArrayList<Integer> randomSeat = new ArrayList<Integer>();

	//	private final boolean needSetRoomInfo = true;

	/**
	 * 设置房间大小盲基础信息
	 * 
	 * @param _data
	 */
	public void requestSetRoomInfo() {
		synchronized (dataPacket) {
			this.setCmd(Protocol.GameRoomCmd);
			this.writeBegin();
			this.writeByte((byte) 100);
//			this.writeString(this.name + "自动设置");
			this.writeInt(this.curRoomId);
			this.writeInt(RandomUtil.next(3, 10));
			this.writeInt(100);
			this.writeInt(200);
			this.writeInt(1000);
			this.writeInt(5000);
			this.writeEnd();
			this.SendData();
		}
	}

	private final int lastSeatId = 0;

	private void requestFastBuyIn() {
		//		Log.debug(this + "准备坐下!");
		// if (needSetRoomInfo && lastSeatId == 0) {
		// if (isEmpty()) {
		// Log.debug("当前房间人为空，且配置需要设置" + this.curRoomId);
		// lastSeatId = 5;
		// requestSetRoomInfo();
		// return;
		// }
		// } else {
		// lastSeatId = 0;
		// }
		int newSeatIndex = 0;
		randomSeat.clear();
		for (int i = 0; i < arrRoomSeat.length; i++) {
			if (this._arrSitInfo[arrRoomSeat[i] - 1] == null) {
				randomSeat.add(arrRoomSeat[i]);
			}
		}
		if (randomSeat.size() < 1) {
			Log.error(this + "当前房间坐位已满");

			// 换其他房间
			return;
		}
		newSeatIndex = randomSeat.get(RandomUtil.next(randomSeat.size()));
		if (newSeatIndex != 0) {
			requestSitDown(newSeatIndex, _objRoom.maxStake);
//			Log.error(this + "请求坐:" + newSeatIndex);
		} else {
			Log.error("房间坐位已满！");
		}
	}

	/**
	 * 机器请求坐下，失败10次，退出，收到退出请求后清0
	 */
	int sitErrCount = 0;

	private void requestSitDown(int newSeatIndex, float maxStake) {
		//		int roomid = this.curRoomId;
		synchronized (this.dataPacket) {
			this.setCmd(Protocol.EnterRoomCmd);
			this.writeBegin();
			this.writeByte((byte) 2);
			this.writeInt(newSeatIndex);
			this.writeFloat(maxStake);
			//StatusList.append("我请求坐seat" + newSeatIndex);
			this.writeEnd();
			this.SendData();
		}
	}

	public void responseRoomInfoCmd() {
		errId = this.readByte();
		if (errId == 0) {
			this.readEnd();
			return;
		}
		/*int dealer = */this.readInt(); // 发牌者
		_objRoom.seat = this.readInt(); // 坐位数
		_objRoom.bettime = this.readByte(); // 倒计时
		int publicCardLen = this.readInt(); // 牌长
		String[] arrPublicCard = new String[publicCardLen];
		int i = 0;
		while (i < publicCardLen) {
			arrPublicCard[i] = this.readString();
			i++;
		}
		// 发牌消息
		int bonusPoolLen = this.readInt(); // 奖金池长度
		int[] arrBonusPool = new int[bonusPoolLen];
		i = 0;
		while (i < bonusPoolLen) {
			arrBonusPool[i] = this.readInt(); // 池里押注的金额
			i++;
		}
		/*int isPlaying = */this.readInt(); //
		/*int curSeatId = */this.readInt();
		/*int time = */this.readInt(); // 倒计时
		int playerNum = this.readInt();
		i = 0;
		int gseatId;
		int guserid;
		PlayerVo objPlayer;
		while (i < playerNum) {
			gseatId = this.readInt();
			guserid = this.readInt();
			objPlayer = this.getInRoomPlayer(guserid);
			if (objPlayer == null) {
				objPlayer = new PlayerVo();
			}
			objPlayer.seatId = gseatId;
			objPlayer.state = this.readInt();
			objPlayer.lastAction = this.readInt();
			objPlayer.callChip = this.readFloat();
			objPlayer.stake = this.readFloat();
			i++;
		}
		this.readEnd();
		//		//StatusList.append(String.format("curroom status,room:%s isPlaying:%s,seat:%s playerNum:%s", _objRoom.name, isPlaying, _objRoom.seat, playerNum));
		// 请求坐下
		// 延时坐下
		requestFastBuyIn();
	}

	public void responseRoomPlayer() {
		int playerCount = this.readInt();
		//		Log.debug(String.format("[%s] %s", this, "当前房间玩家数" + playerCount));
		int count = 0;
		int guserid;
		int gameseatid;
		PlayerVo playerVo = null;
		while (count < playerCount) {
			gameseatid = this.readInt();
			guserid = this.readInt();
			if (guserid < 1)
				throw new IllegalArgumentException("用户id大于0");
			if (guserid == this.userid) {
				playerVo = this.curPlayer;
			} else {
				playerVo = new PlayerVo();
				playerVo.userid = guserid;
			}
			playerVo.seatId = gameseatid;
			playerVo.sex = this.readByte();
			playerVo.initSex = playerVo.sex;
			playerVo.name = this.readString();
			playerVo.icon = this.readString();
			//			playerVo.vip = this.readInt();
			//			playerVo.gold = this.readInt();
			playerVo.money = this.readFloat();
			//			playerVo.sumGame = this.readInt();
			//			playerVo.winGame = this.readInt();
			//			playerVo.rank = this.readInt();
			//			playerVo.winRank = this.readInt();
			//			playerVo.giftPcate = this.readInt();
			//			playerVo.giftPframe = this.readInt();
			//			playerVo.banSpeak = this.readInt();
			//			playerVo.yellowvip = this.readInt();
			//			playerVo.isyearvip = this.readInt();
//			Log.debug("responseRoomPlayer" + playerVo);
			this.inRoom(playerVo);
			//			//StatusList.append("inRoom user" + playerVo.name);
			//			//StatusList.append(playerVo.name + ",");
			if (gameseatid > 0) {
				//StatusList.append("sitdown user" + playerVo.seatId);
				this.sitDown(playerVo);
			}
			count = count + 1;
		}
		this.readEnd();
	}

	private final String[] _arrMyCard = new String[2];
	private final String[] _arPublicCard = new String[5];
	private final String[] arrHuase = new String[] { "方块", "梅花", "红桃", "黑桃" };

	public void CMD_GAME_OVER() {
		//		Log.debug(this + "本牌局结束，等待下一局");
		this.readEnd();
		//		if (curRoomPlayCount >= totalRoomPlayCount) {
		//			requestOutRoom();
		//		}
	}

	public void CMD_POTS() {
		/*不需要显示int potId = this.readInt();
		int cardType = this.readInt();
		float winLen = this.readFloat();
		PlayerVo playerVo;
		int i = 0;
		int winSeatId;
		int userid;
		float potMoney;
		float stake;
		String backCard1;
		String backCard2;
		String card1;
		String card2;
		String card3;
		String card4;
		String card5;
		while (i < winLen) {
			winSeatId = this.readInt();
			userid = this.readInt();
			potMoney = this.readFloat();
			stake = this.readFloat();
			backCard1 = this.readString();
			backCard2 = this.readString();
			card1 = this.readString();
			card2 = this.readString();
			card3 = this.readString();
			card4 = this.readString();
			card5 = this.readString();
			playerVo = this.getInRoomPlayer(userid);
			if (playerVo != null) {
				if (card1.length() == 2) {
					// %NAME% 牌型为%VALUE%
		//					Log.debug(playerVo + "坐位" + winSeatId + " 筹码" + stake + " 手牌 " + backCard1 + " " + backCard2 + " 牌型为" + cardType + " 最大牌 " + card1 + " " + card2 + " " + card3 + " " + card4 + " " + card5);
				}
				if (potId == 0) {
		//					Log.debug(playerVo + " 赢得主池" + potMoney);
				} else {
					// %NAME% 赢得第%NUM%边池%VALUE%
		//					Log.debug(playerVo + " 赢得第" + (potId + 1) + "边池" + potMoney);
				}
			}
			i++;
		}*/
		this.readEnd();
	}

	class PlayerCard {
		public int seatId;
		public int isWin;
		public String selfcard1;
		public String selfcard2;
		public String[] wincard = new String[5];
		public int cardType;

		public String playerCard() {
			return String.format(" 坐位%s 是否赢:%s 牌%s %s 牌型:%s", this.seatId, this.isWin, this.selfcard1, this.selfcard2, GamePool.arrCardType[this.cardType]);
		}

		public String winCard() {
			return String.format(" 坐位%s  最大牌%s %s %s %s %s", this.seatId, this.wincard[0], this.wincard[1], this.wincard[2], this.wincard[3], this.wincard[4]);
		}
	}

	public void CMD_SHOW() {
		//		Log.debug(this + "游戏结束，显示底牌");
		/*没有重要数据
		int playerNum = this.readInt();
		ArrayList<PlayerCard> arrPlayCard = new ArrayList<PlayerCard>();
		int i = 0;
		PlayerCard playerCard;
		while (i < playerNum) {

			playerCard = new PlayerCard();
			playerCard.seatId = this.readInt();
			playerCard.isWin = this.readInt();
			playerCard.selfcard1 = this.readString();
			playerCard.selfcard2 = this.readString();
			playerCard.cardType = this.readInt();
			arrPlayCard.add(playerCard);
			Log.debug(this + playerCard.playerCard());
			i++;
		}
		int winCardNum = this.readInt();
		i = 0;
		while (i < winCardNum) {

			playerCard = new PlayerCard();
			playerCard.seatId = this.readInt();
			playerCard.wincard[0] = this.readString();
			playerCard.wincard[1] = this.readString();
			playerCard.wincard[2] = this.readString();
			playerCard.wincard[3] = this.readString();
			playerCard.wincard[4] = this.readString();
			arrPlayCard.add(playerCard);
		//			Log.debug(this + playerCard.winCard());
			i++;
		}*/
		this.readEnd();
	}

	public void CMD_CUR_POT() {
		/*显示信息,不需要
		 * String cards = "";
		int potLen = this.readInt();
		int potNum;
		float potMoney;
		for (int i = 0; i < potLen; i++) {
			potNum = this.readInt();
			potMoney = this.readFloat();
		//			Log.debug(this + "第" + (potNum + 1) + "边池形成,总额" + potMoney);
		}*/
		this.readEnd();
	}

	public void CMD_SNAPCARDS_FLOP() {
		/*String cards = "";
		for (int i = 0; i < 3; i++) {
			_arPublicCard[i] = this.readString();
			cards += arrHuase[GamePool.countCardHuaSe(_arPublicCard[i].substring(1, 2)) - 1] + _arPublicCard[i].substring(0, 1) + ",";
		}*/
		this.readEnd();
		//		Log.debug(this + "翻牌" + cards);
	}

	public void CMD_SNAPCARDS_TURN() {
		/*_arPublicCard[3] = this.readString();
		String cards = arrHuase[GamePool.countCardHuaSe(_arPublicCard[3].substring(1, 2)) - 1] + _arPublicCard[3].substring(0, 1) + ",";
		*/
		this.readEnd();
		//		Log.debug(this + "转牌" + cards);
	}

	public void CMD_SNAPCARDS_RIVER() {
		/*_arPublicCard[4] = this.readString();
		String cards = arrHuase[GamePool.countCardHuaSe(_arPublicCard[4].substring(1, 2)) - 1] + _arPublicCard[4].substring(0, 1) + ",";
		*/this.readEnd();
		//		Log.debug(this + "河牌" + cards);
	}

	public void CMD_OPERATION_SUCC() {
		int seatId = this.readInt(); // 当前坐位id
		float stake = this.readFloat(); // 玩家的筹码
		float callChip = this.readFloat(); // 桌面最小叫多少
		int lastAction = this.readInt(); // 最小大加注多少
		this.readEnd();
		PlayerVo playerVo = this.getSitPlayerBySeatId(seatId);
		playerVo.stake = stake;
		playerVo.callChip = callChip;
		playerVo.lastAction = lastAction;
		//		Log.debug(this + " 坐位" + seatId + " name " + playerVo.name + " 操作" + GamePool.getLastAction(lastAction) + " 下注" + callChip + " 剩筹码" + stake);
	}

	ArrayList<Integer> lastAction = new ArrayList<Integer>();

	public int step;
	public int sendStep;
	public int curSeat;

	public void responseCMD_OPERATION_NEXT() {
		step = this.readInt(); // 当前坐位id
		curSeat = this.readInt(); // 当前坐位id
		float minCall = this.readFloat(); // 桌面最小叫多少
		float maxRaise = this.readFloat(); // 最小大加注多少
		float minRaise = this.readFloat(); // 最小加注多少
		float stake = this.readFloat(); // 玩家的筹码
		this.readEnd();
		if (operateNextTime == 0)
			operateNextTime = System.currentTimeMillis();
		//		Log.debug(this + ",轮到坐位出牌,gameSeatId:" + gameSeatId);
		if (this.seatId != curSeat) {
			this.stepMemo = "seatId:" + this.seatId + " !=curSeat:" + curSeat;
			return;
		}
		this.stepMemo = "出牌seatId:" + this.seatId + "==curSeat:" + curSeat;
		this.curPlayer.stake = stake;
		// PlayerVo playerVo=this.getSitPlayerBySeatId(seatId);
		//		Log.debug(this.curPlayer.name + "----------->>最小叫:" + minCall + " 最大叫:" + maxRaise + " 最小加注:" + minRaise + " 筹码:" + stake + " 先前下注:" + this.curPlayer.callChip + " 最大筹码:" + this._objRoom.maxStake);
		boolean canLook = false;
		boolean canRaise = false;
		boolean canAllin = false;
		boolean canCall = false;
		// 看牌，加注，放弃
		if (minCall == 0) {
			canLook = true;
			canCall = false;
		} else {
			canLook = false;
			canCall = true;
		}
		// 加注，放弃
		// else{
		//
		// }
		if (this.curPlayer.stake + this.curPlayer.callChip < minCall) {
			canRaise = false;
			canCall = false;
		}
		if (this.curPlayer.stake + this.curPlayer.callChip > minRaise) {
			if (maxRaise != minRaise && this.curPlayer.stake + this.curPlayer.callChip > maxRaise) {
				canRaise = true;
			}

		} else {
			canRaise = false;
		}
		if (maxRaise == minRaise) {
			if (this.curPlayer.stake + this.curPlayer.callChip <= maxRaise) {
				canAllin = true;
			} else {
				canAllin = false;
			}
			canRaise = false;
		}
		// /** * 看牌 */ CHECK(1),///** * 弃牌 */FOLD(2),///** * 跟注 */CALL(3), // /
		// *加注 */RAISE(4),///** * 全押 */ ALLIN(5);//
		lastAction.clear();
		lastAction.add(2);
		if (canLook) {
			lastAction.add(1);
		}
		if (canCall) {
			lastAction.add(3);
		}
		if (canRaise) {
			lastAction.add(4);
		}
		if (canAllin) {
			lastAction.add(5);
		}
		int action = lastAction.get(RandomUtil.next(lastAction.size()));
		float chip = 0;
		if (action == 4) {
			chip = Math.round(RandomUtil.next(minRaise, maxRaise));
		}
		//		Log.debug(this + "延时5秒, 看牌 *CHECK(1), 弃牌 */FOLD(2), 跟注	 */CALL(3),*加注  RAISE(4),* 全押 	ALLIN(5);进行随机操作!action:" + action + " chip " + chip);
		stepMemo = "time push requestOperate step:" + this.step;
		TimerMgr.push(new requestOperate(this, action, chip), 5);
	}

	String stepMemo = "";

	class requestOperate implements Runnable {
		Robot robot;
		int action;
		float chip;

		public requestOperate(Robot _robot, int _action, float _chip) {
			this.action = _action;
			this.chip = _chip;
			this.robot = _robot;
		}

		public void run() {
			synchronized (robot.dataPacket) {
				robot.setCmd(Protocol.GameRoomCmd);
				robot.writeBegin();
				robot.writeByte((byte) 103);
				robot.writeInt(robot.step);
				robot.writeInt(action);
				robot.writeFloat(chip);
				robot.writeEnd();
				robot.SendData();
				robot.sendStep = robot.step;
				robot.stepMemo = "time run requestOperate step:" + robot.step;
			}
		}

	}

	public void requestOperate(int action, int chip) {

	}

	public void responseStartGame() {
		this.step = 0;
		this.sendStep = 0;
		stepMemo = "game start";
		/*int dealer = */this.readInt();
		_arrMyCard[0] = this.readString();
		_arrMyCard[1] = this.readString();
		int playingNum = this.readInt();
		int i = 0;
		PlayerVo plyerVo;
		while (i < playingNum) {
			plyerVo = this.getSitPlayerBySeatId(this.readInt());// seatId
			plyerVo.callChip = this.readFloat();
			// plyerVo.callType=1;
			i++;
		}
		this.readEnd();
		// 取消定时器退出房间
		curRoomPlayCount++;
		/*if (requestOutRoomHandler != null) {
			requestOutRoomHandler.cancel(true);
			requestOutRoomHandler = null;
		}*/
		//		Log.debug(this + "新牌局开始,当前房玩游戏次数:" + curRoomPlayCount);
	}

	/**
	 * 设置房间大小盲基础信息
	 */
	public void responseSetRoomInfo() {
		errId = this.readByte();
		if (errId != 0) {
			//			Log.debug(this + "服务端返回房间设置错误!roomid" + this.curRoomId);
			//this.StatusList.append("服务端返回房间设置错误!roomid" + this.curRoomId);
			this.readEnd();
			// 再次检查并坐下
			sitErrCount++;
			Log.debug(this + "坐下失败！sitErrCount" + sitErrCount);
			if (sitErrCount < totalTrySitError) {
				// 重新寻找新坐位,坐下10次，退出房间，进10次，退出
				requestFastBuyIn();
			}
//			else {
//				// 请求退出房间
//				requestOutRoom();
//			}
			return;
		}
		/*String roomname = */this.readString();
		int roomid = this.readInt();
		int seat = this.readInt();
		int minBlind = this.readInt();
		int maxblind = this.readInt();
		int minStake = this.readInt();
		int maxStake = this.readInt();
		//		RoomVo room = roomMap.get(roomid);
		RoomVo room = roomMap[roomid];
		if (room != null) {
			room.seat = seat;
			room.minBlind = minBlind;
			room.maxblind = maxblind;
			room.minStake = minStake;
			room.maxStake = maxStake;
		}

		if (this._objRoom != null && roomid == this.curRoomId) {
			Log.debug(this + "房间基础信息发生改变");
			//this.StatusList.append("设置房间成功," + this.curRoomId);
			if (this.seatId == 0 && this.lastSeatId == 5) {
				requestFastBuyIn();
			} else {
				Log.debug("不做坐下动作");
			}
		} else {
			Log.debug("服务端返回的房间不是当前房间!,更新其他房间");
		}
		this.readEnd();
	}

	public void requestStandup() {
		synchronized (this.dataPacket) {
			this.setCmd(Protocol.EnterRoomCmd);
			this.writeBegin();
			this.writeByte((byte) 5);
			this.writeEnd();
			this.SendData();
		}
	}

	public void requestOutRoom() {
		synchronized (this.dataPacket) {
			this.setCmd(Protocol.EnterRoomCmd);
			this.writeBegin();
			this.writeByte((byte) 3);
			this.writeEnd();
			this.SendData();
		}
	}

	public void StandUpCmd() {
		int gameseatId = this.readInt();
		float money = this.readFloat();
		/*int isSystem = */this.readInt();
		this.readEnd();
		PlayerVo playerVo2 = this.getSitPlayerBySeatId(gameseatId);
		if (playerVo2 == null)
			return;
		PlayerVo playerVo1 = this.getInRoomPlayer(playerVo2.userid);
		if (playerVo1 == null)
			return;
		playerVo1.money = money;
		this.standUp(gameseatId);
		if (playerVo1.userid == this.curPlayer.userid) {
			//StatusList.append("自己站起");
			this.curPlayer.money = money;
			this.seatId = 0;
			// //this.StatusList.append(" seatid 0 ");
			// 机器人没钱被T,
			curRoomKick++;
			Log.debug(this + "[被T起了次数]" + curRoomKick);
			//踢了继续做下去
			requestFastBuyIn();
			//			if (curRoomKick >= totalRoomKick) {
			//				Log.debug(this + "[被T起了次数已多,请求退出该房]");
			//				requestOutRoom();
			//			} else {
			//				requestFastBuyIn();
			//			}
		} else {
			//			//StatusList.append("他seat站起" + gameseatId);
		}
		playerVo1.state = 0;
		//		Log.debug("玩家站起" + playerVo1);
	}

	public void CMD_OUT_GAME_ROOM() {
		errId = this.readByte();
		if (errId == 0) {
			Log.debug("退出房间错误");
		}
		int userid = this.readInt();
		this.readEnd();
		this.outRoom(userid);
		PlayerVo playerVo = this.getInRoomPlayer(userid);
		if (playerVo != null) {
			Log.debug(playerVo + "用户离开房间");
		}

	}

	public void CMD_ROOMPLAYERNUMCHANGE() {
		/*
		 不需要
		int roomid = this.readInt(); // roomid
		int playerNum = this.readInt();
		this.readEnd();
		if(roomMap!=null&&roomMap.length>=roomid)
		RoomVo room = roomMap[roomid];
		if (room != null) {
			room.playerNum = playerNum;
		}*/
		//		Log.debug("房间" + roomid + "坐位人数" + playerNum);
		//		//StatusList.append("room num" + roomid + ":" + playerNum);
		this.readEnd();
	}

	public void CMD_ROOMINFOUPDATE() {
		/*errId = this.readByte();
		if (errId != 0) {
			Log.debug("responseRoomUpdate服务端返回设置错误!");
		} else {
			int roomid = this.readInt(); // roomid
			RoomVo room = roomMap[roomid];
			if (room != null) {
				Log.debug("CMD_ROOMINFOUPDATE roomid" + roomid);
				room.name = this.readString(); // roomname
				room.seat = this.readInt(); // seat
				room.minBlind = this.readFloat(); // minStake
				room.maxblind = this.readFloat(); //
				room.minStake = this.readFloat(); // minStake
				room.maxStake = this.readFloat();
				room.playerNum = this.readInt();
				if (_objRoom != null && _objRoom.id == roomid) {
					_objRoom.seat = seat;
				}
				// Log.debug("房间基础信息发生改变,");
			}
		}*/
		this.readEnd();
	}

	long responseSitdownTime = 0;
	long operateNextTime = 0;

	public void responseSitdown() {
		errId = this.readByte();
		if (errId == 0) {
			this.readEnd();
			sitErrCount++;
			Log.debug(this + "坐下失败！sitErrCount" + sitErrCount);
			//StatusList.append(" 坐失败sitErrCount" + sitErrCount + " ");
			if (sitErrCount < totalTrySitError) {
				// 重新寻找新坐位,坐下10次，退出房间，进10次，退出
				stepMemo = "请求坐,已经error:" + sitErrCount;
				requestFastBuyIn();
			} else {
				stepMemo = "停止请求坐,已经10次";
			}
			/*else {
			}
			Log.debug(this + "stop sit");
			// 请求退出房间
			// requestOutRoom();
			}*/

		} else {
			int guserid = this.readInt();
			PlayerVo objPlayer = this.getInRoomPlayer(guserid);
			if (objPlayer != null) {
				objPlayer.seatId = this.readInt();
				objPlayer.stake = this.readFloat();
				objPlayer.money = this.readFloat();
				objPlayer.callChip = 0;
				if (this.userid == guserid) {
					this.seatId = objPlayer.seatId;
					if (responseSitdownTime == 0)
						responseSitdownTime = System.currentTimeMillis();
					//StatusList.append(" 我坐成功seatId" + seatId);
					// 等待3分钟，换房间
					// requestOutRoomHandler = TimerMgr.push(new Runnable() {
					// public void run() {
					// requestOutRoom();
					// }
					// }, roomSitWaitTime, TimeUnit.MINUTES);
				} else {
					//					//StatusList.append(" 新人坐成功seatId" + objPlayer.seatId);
				}
				this.sitDown(objPlayer);
				// Log.debug("欢迎" + objPlayer.name + "坐下");
			} else {
				//				//StatusList.append(" 他坐成功,不在inroom里userid" + guserid);
			}

			this.readEnd();
		}
	}

	/**
	 * 玩家在坐位上等3分钟，没有人来就离开房间
	 */
	int roomSitWaitTime = 3;
	//	ScheduledFuture requestOutRoomHandler;
	/**
	 * 玩家连续10次坐下失败，就退出该房间
	 */
	int totalTrySitError = 10;
	/**
	 * 机器人进了10次房间，就结束生涯
	 */
	int totalEnterRoomCount = 10;
	int curEnterRoomCount = 0;
	/**
	 * 机器人一个房间玩20把就退出
	 */
	int totalRoomPlayCount = 20;
	int curRoomPlayCount = 0;
	/**
	 * 机器人在本房输光了10次，就退出房间
	 */
	int totalRoomKick = 10;
	int curRoomKick = 0;

	/**
	 * 当前房间进人
	 */
	public void responseInGAameRoomCmd() {
		errId = this.readByte();
		if (errId == 0) {
			Log.debug(String.format("[%s] %s", this, "responseInGAameRoomCmd Error"));
		} else {
			int guserid = this.readInt();
			PlayerVo playerVo;
			if (guserid == this.userid) {
				playerVo = this.curPlayer;
			} else {
				playerVo = new PlayerVo();
				playerVo.userid = guserid;
			}
			//			playerVo.personId = this.readInt();
			playerVo.sex = this.readByte();
			playerVo.initSex = playerVo.sex;
			playerVo.name = this.readString();
			playerVo.icon = this.readString();
			//			playerVo.vip = this.readInt();
			//			playerVo.gold = this.readInt();
			playerVo.money = this.readFloat();
			//			playerVo.sumGame = this.readInt();
			//			playerVo.winGame = this.readInt();
			//			playerVo.rank = this.readInt();
			//			playerVo.winRank = this.readInt();
			//			playerVo.giftPcate = this.readInt();
			//			playerVo.giftPframe = this.readInt();
			//			playerVo.banSpeak = this.readInt();
			//			playerVo.yellowvip = this.readInt();
			//			playerVo.isyearvip = this.readInt();
			inRoom(playerVo);
			//			Log.debug("玩家进入房间" + playerVo);
			//			//StatusList.append(" new come" + playerVo.name + ",");
		}
		this.readEnd();

	}

	public void responseLogin() {
//		Log.debug("收到登陆消息");
		short type = this.readByte();
		if (type == 0) {
			Log.debug(this + "登陆成功前");
			this.userid = this.readInt();
			this.username = this.readString();
			this.name = this.readString();
			this.sex = this.readByte();
			//			this.email = this.readString();
			//			this.moible = this.readString();
			//			this.score = this.readInt();
			// headimage
			int len = this.readInt();
			while (len > 0) {
				this.readByte();
			}
			// headimage
			this.money = this.readFloat();
			//			this.gold = this.readInt();
			this.readEnd();
			this.curPlayer.userid = userid;
			this.curPlayer.userName = username;
			this.curPlayer.name = name;
			this.curPlayer.sex = sex;
			this.curPlayer.money = money;
//			Log.debug(this + "登陆成功");
			//this.StatusList.append("登陆成功");
			RobotMgr.run(new Runnable() {
				public void run() {
					requestRoomList();
				}
			});
		} else {
			this.readEnd();
//			Log.debug(this + "登陆失败");
			//this.StatusList.append("登陆失败");
			RobotMgr.close(this);
		}
	}

	public boolean SendData(short cmdId, ByteBuffer bytes) {
		//		Log.debug(String.format("========>准备发命令:%s name:%s bytes[%s]", cmdId, RobotMgr.cmdSocket.get(cmdId), "..."));
		bytes.position(0);
		synchronized (this.SendBuffer) {

			if (SendBuffer.remaining() < bytes.remaining()) {
				Log.error(String.format("[Robot][%s]的发送缓冲已经不足,消息长度[%s]，请检查!", this, bytes.remaining()));
				return false;
			}
			SendBuffer.putInt(29099);
			SendBuffer.putInt(bytes.remaining() + 22);// length
			SendBuffer.putShort(cmdId);// cmd
			SendBuffer.putInt(1);// temp1
			SendBuffer.putInt(2);// temp2
			SendBuffer.putInt(3);// temp3
			SendBuffer.put(bytes);
			setHasSendData(true);
		}
		try {
			send();
		} catch (IOException e) {
			e.printStackTrace();
			Log.error(e);
		}
		return true;
	}

	public void send() throws IOException {
		if (!this.getHasSendData().get()) {
			return;
		}
		synchronized (this.SendBuffer) {
			SendBuffer.flip(); // 把极限设为位置，把位置设为零
			while (this.getHasSendData().get()) {
				socketChannel.write(SendBuffer); // 发送数据，写的时候覆盖了之前的数据，
				// 一个完整包长度不够，设置没有数据
				if (SendBuffer.remaining() <= 0) {
					setHasSendData(false);
				}
				SendBuffer.compact(); // 删除已经发送的数据
			}
		}
	}

	public boolean SendData() {
		return SendData(dataPacket.cmdId, dataPacket.byteBuffer);
	}

	public void register() {
		// 接收和发送数据
		try {
			RobotMgr.selectorLock.lock();
			socketChannel.register(RobotMgr.selector, SelectionKey.OP_READ, this);
			// socketChannel.register(RobotMgr.selector, SelectionKey.OP_READ |
			// SelectionKey.OP_WRITE, this);
			RobotMgr.incrementRobot();
		} catch (ClosedChannelException e1) {
			e1.printStackTrace();
		} finally {
			RobotMgr.selectorLock.unlock();
		}
	}

	public AtomicBoolean getHasReceiveData() {
		return hasReceiveData;
	}

	public void setHasReceiveData(Boolean hasReceiveData) {
		this.hasReceiveData.set(hasReceiveData);
	}

	public AtomicBoolean getHasSendData() {
		return hasSendData;
	}

	public void setHasSendData(Boolean hasSendData) {
		this.hasSendData.set(hasSendData);
	}

	public int login() {
		return 0;
	}

	public int getUserId() {
		return this.userid;
	}

	public long getLastSyncTime() {
		return this.lastSyncTime;
	}

	public void setLastSyncTime(long lastSyncTime) {
		this.lastSyncTime = lastSyncTime;
	}

	public int getAcceleratCount() {
		return this.acceleratCount;
	}

	public void setAcceleratCount(int acceleratCount) {
		this.acceleratCount = acceleratCount;
	}

	public void addAcceleratCount() {
		this.acceleratCount += 1;
	}

	@Override
	public String toString() {
		/*String roomPlayers = "";
		for (PlayerVo p : this._arrInRoomPlayer) {
			roomPlayers += p.name + ",";
		}
		return String.format("【Robot userid %s username %s name %s.RoomId %s, SeatId:%s [PlayerVo:%s]】[roomPlayers %s]【status:%s】", this.userid, username, this.name, this.curRoomId, this.seatId, this.curPlayer, roomPlayers, this.StatusList.toString());
		*/
		return this.name;
	}

	public String getInfo() {
		return String.format("【Robot userid %s username %s name %s.connected:%s,RoomId %s, [SeatId:%s,curSeat:%s,AcceptStep:%s,SendStep:%s,stepMemo:%s,sitTime:%s,nextTime:%s] [PlayerVo:%s]】", this.userid, username, this.name, this.socketChannel.isConnected(), this.curRoomId, this.seatId, this.curSeat, this.step, this.sendStep, stepMemo, this.responseSitdownTime, this.operateNextTime, this.curPlayer);
	}

	public ByteBuffer getBytes() {
		return dataPacket.byteBuffer;
	}

	public void setCmd(short cmd) {
		this.dataPacket.cmdId = cmd;
	}

	public short getCmd() {
		return this.dataPacket.cmdId;
	}

	public short getRecCmd() {
		return this.recDataPacket.cmdId;
	}

	public void setRecCmd(short cmd) {
		this.recDataPacket.cmdId = cmd;
	}

	// 写操作
	// public ByteBuffer wrap(byte[] bytes) {
	//
	// return dataPacket.wrap(bytes);
	// }
	//
	// public ByteBuffer wrap(String msg) {
	// return dataPacket.wrap(msg);
	// }

	public void writeBegin() {
		dataPacket.writeBegin();
	}

	// public void writeBegin(int size) {
	// dataPacket.writeBegin(size);
	// }

	public void writeByte(byte value) {
		dataPacket.writeByte(value);
	}

	public void writeShort(Short value) {
		dataPacket.writeShort(value);
	}

	public void writeInt(int value) {
		dataPacket.writeInt(value);
	}

	public void writeFloat(float value) {
		dataPacket.writeFloat(value);
	}

	public void writeString(String msg) {
		dataPacket.writeString(msg);
	}

	public void writeEnd() {
		dataPacket.flip();
	}

	// 读取操作
	public void readEnd() {
//		recDataPacket.byteBuffer.compact();
		recDataPacket.clear();
		this.isUseRecDataPacket = false;
	}

	public char readChar() {
		return recDataPacket.readChar();
	}

	public byte readByte() {
		return recDataPacket.readByte();
	}

	public void readBytes(byte[] dst, int offset, int length) {
		dataPacket.readBytes(dst, offset, length);
	}

	public float readFloat() {
		return recDataPacket.readFloat();
	}

	public long readLong() {
		return recDataPacket.readLong();
	}

	public double readDouble() {
		return recDataPacket.readDouble();
	}

	public int readInt() {
		return recDataPacket.readInt();
	}

	public short readShort() {
		return recDataPacket.readShort();
	}

	public String readString() {
		return recDataPacket.readString();
	}

	public ByteBuffer pack() {
		int l = length();
		ByteBuffer byteBufferer = ByteBuffer.allocate(l);
		if (position() > 0) {
			flip();
		}
		byteBufferer.put(array(), 0, l);
		byteBufferer.flip();
		return byteBufferer;
	}

	public byte[] array() {
		return dataPacket.array();
	}

	public int position() {
		return dataPacket.position();
	}

	public void position(int newPosition) {
		dataPacket.position(newPosition);
	}

	public int remaining() {
		return dataPacket.remaining();
	}

	public int limit() {
		return dataPacket.limit();
	}

	public void flip() {
		dataPacket.flip();
	}

	public void clear() {
		dataPacket.clear();
	}

	/**
	 * 
	 * @return
	 */
	public int length() {
		return dataPacket.length();
	}

	/**
	 * 
	 * 
	 * @return
	 */
	public int totalSize() {
		return dataPacket.totalSize();
	}

	public void outInfo(byte[] bytes) {
		dataPacket.outInfo(bytes);
	}

	public void inRoom(PlayerVo player) {
		if (!this._arrInRoomUserid.contains(player.userid)) {
			this._arrInRoomPlayer.add(player);
			_arrInRoomUserid.add(player.userid);
		}
		// Log.debug(player + "进入房间,当前人数" + _arrInRoomPlayer.size());
		return;
	}

	/**
	 * 拷贝玩家信息到副本
	 * 
	 * @param playerVo
	 */
	public void sitDown(PlayerVo playerVo) {
		this._arrSitInfo[(playerVo.seatId - 1)] = playerVo;
		return;
	}

	public PlayerVo getSitPlayerBySeatId(int seatId) {
		PlayerVo playerVo = this._arrSitInfo[(seatId - 1)];
		if (playerVo == null) {
			playerVo = new PlayerVo();
		}
		return playerVo;
	}

	/**
	 * 根据用户id查询用户在坐位的游戏数据
	 * 
	 * @param userid
	 * @return
	 */
	public PlayerVo getSitPlayerByMid(int userid) {
		PlayerVo playerVo = null;
		int total = this._arrSitInfo.length;
		int index = 0;
		while (index < total) {

			if (this._arrSitInfo[index] != null && this._arrSitInfo[index].userid == userid) {
				playerVo = this._arrSitInfo[index];
				break;
			}
			index = index + 1;
		}
		if (playerVo == null) {
			playerVo = new PlayerVo();
		}
		return playerVo;
	}

	/**
	 * 玩家离开房间
	 * 
	 * @param userid
	 */
	public void outRoom(int userid) {
		int siteIndex = 0;
		int index = 0;
		PlayerVo playerVo = null;
		int roomPlayerCount = this._arrInRoomPlayer.size();
		if (userid == this.curPlayer.userid) {
			//this.StatusList.append(" 自己离开房间 roomid 0 ");
			this.curRoomId = 0;
			_objRoom = null;
			Log.debug("退出房间，当前房间状态即将清0，curEnterRoomCount:" + curEnterRoomCount + " 坐错误数" + sitErrCount + " 游戏次数:" + curRoomPlayCount);
			sitErrCount = 0;
			curRoomPlayCount = 0;
			curRoomKick = 0;
			siteIndex = 0;
			while (siteIndex < 9) {

				this.standUp((siteIndex + 1));
				siteIndex = siteIndex + 1;
			}
			this._arrInRoomPlayer.clear();
			_arrInRoomPlayer.clear();
			if (curEnterRoomCount >= totalEnterRoomCount) {
				// 机器人使命完成，结束掉吧
				Log.debug("机器人使命完成，结束掉吧");
			} else {
				requetEnterRoom();
			}
		} else {
			//			//this.StatusList.append(" 他seat离开房间 userid" + userid);
			index = 0;
			_arrInRoomPlayer.remove(Integer.valueOf(userid));
			while (index < roomPlayerCount) {

				playerVo = this._arrInRoomPlayer.get(index);
				if (playerVo.userid == userid) {
					this._arrInRoomPlayer.remove(playerVo);
					break;
				}
				index = index + 1;
			}
		}
		return;
	}

	/**
	 * 根据用户id找到玩家
	 * 
	 * @param userId
	 * @return
	 */
	public PlayerVo getInRoomPlayer(int userId) {
		// Log.debug("在房间用户数据查找userid " + userId);
		for (PlayerVo palyerVo : _arrInRoomPlayer) {
			if (palyerVo.userid == userId) {
				return palyerVo;
			}
		}
		return null;
	}

	public void standUp(int seatId) {
		PlayerVo sitInfo = this._arrSitInfo[seatId - 1];
		if (sitInfo != null) {
			sitInfo.lastAction = 100;// GameData.LOOK_ON;
			sitInfo.state = 100;// GameData.LOOK_ON;
			//			Log.debug("玩家站起来了:" + sitInfo);
		}
		this._arrSitInfo[(seatId - 1)] = null;
		return;
	}

	public int[] getRoomSit(int roomType) {
		int[] arrSeatId = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		switch (roomType) {
		case 3: {
			return new int[] { 2, 5, 8 };
		}
		case 4: {
			return new int[] { 1, 3, 7, 9 };
		}
		case 5: {
			return new int[] { 1, 3, 5, 7, 9 };
		}
		case 6: {
			return new int[] { 1, 2, 3, 7, 8, 9 };
		}
		case 7: {
			return new int[] { 1, 2, 3, 5, 7, 8, 9 };
		}
		case 8: {
			return new int[] { 1, 2, 3, 4, 6, 7, 8, 9 };
		}
		default: {
			break;
		}
		}
		return arrSeatId;

	}

	public boolean isEmpty() {
		boolean isEmpty = true;
		for (PlayerVo player : this._arrSitInfo) {
			if (player != null) {
				isEmpty = false;
				break;
			}
		}
		return isEmpty;
	}
}
